package com.neusoft.resturant.controller;

import com.neusoft.resturant.common.utils.R;
import com.neusoft.resturant.entity.ResDishes;
import com.neusoft.resturant.service.IResDishesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/dish")
public class ResDishesController {
    @Autowired
    private IResDishesService resDishesService;

    /**
     * 查询菜品列表
     */
    @GetMapping("/list")
    public R list(ResDishes resDishes)
    {
        List<ResDishes> list = resDishesService.selectResDishesList(resDishes);
        return R.success(list);
    }


    /**
     * 获取菜品详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id)
    {

        return R.success(resDishesService.selectResDishesById(id));
    }

    /**
     * 新增菜品
     */
    @PostMapping
    public R add(@RequestBody ResDishes resDishes)
    {
        return R.toAjax(resDishesService.insertResDishes(resDishes));
    }

    /**
     * 修改菜品
     */
    @PutMapping
    public R edit(@RequestBody ResDishes resDishes)
    {
        return R.toAjax(resDishesService.updateResDishes(resDishes));
    }

    /**
     * 删除菜品
     */
    @DeleteMapping("/{id}")
    public R remove(@PathVariable Long id)
    {
        return R.toAjax(resDishesService.deleteResDishesById(id));
    }
    
}
